//
//  BBDevice.swift
//  BBLinkiOSProject
//
//  Created by liuzhu on 2018/11/29.
//  Copyright © 2018 liuzhu. All rights reserved.
//

import UIKit

class BBDevice:NSObject,NSCoding{
    @objc var userId:String?
    @objc var deviceId:String?
    @objc var deviceName:String?
    @objc var createTime:NSNumber?
    @objc var updateTime:NSNumber?
    @objc var batteryUsed:NSNumber?
    @objc var lastMileage:NSNumber?
    @objc var mileage:NSNumber?
    @objc var deviceImages:String?
    @objc var status:String?
    
    init(dict:[String:AnyObject]){
        super.init()
        setValuesForKeys(dict)
    }
    
    override func setValue(_ value: Any?, forUndefinedKey key: String) {
        print(key)
    }
    
    func encode(with aCoder: NSCoder) {
        aCoder.encode(userId, forKey: "userId")
        aCoder.encode(deviceId, forKey: "deviceId")
        aCoder.encode(deviceName, forKey: "deviceName")
        aCoder.encode(createTime, forKey: "createTime")
        aCoder.encode(updateTime, forKey: "updateTime")
        aCoder.encode(batteryUsed, forKey: "batteryUsed")
        aCoder.encode(lastMileage, forKey: "lastMileage")
        aCoder.encode(mileage, forKey: "mileage")
        aCoder.encode(deviceImages, forKey: "deviceImages")
        aCoder.encode(status, forKey: "status")
    }
    
    //读取对象
    required init?(coder aDecoder: NSCoder) {
        userId = aDecoder.decodeObject(forKey: "userId")as?String
        deviceId = aDecoder.decodeObject(forKey: "deviceId")as?String
        deviceName = aDecoder.decodeObject(forKey: "deviceName")as?String
        createTime = aDecoder.decodeObject(forKey: "createTime") as?NSNumber
        updateTime = aDecoder.decodeObject(forKey: "updateTime") as?NSNumber
        batteryUsed = aDecoder.decodeObject(forKey: "batteryUsed") as?NSNumber
        lastMileage = aDecoder.decodeObject(forKey: "lastMileage") as?NSNumber
        mileage = aDecoder.decodeObject(forKey: "mileage") as? NSNumber
        deviceImages = aDecoder.decodeObject(forKey: "deviceImages") as? String
        status = aDecoder.decodeObject(forKey: "status") as? String
    }
}
